<?php
// +----------------------------------------------------------------------
// | Tplay [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://tplay.pengyichen.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 听雨 < 389625819@qq.com >
// +----------------------------------------------------------------------


namespace app\admin\controller;

use \think\Db;
use \think\Cookie;
use app\admin\controller\Permissions;
class Form extends Permissions
{
    public function index()
    {
    	
    	return $this->fetch();
    }
    public function excel1()
    {
		ini_set("memory_limit","-1");
		Vendor('PHPExcel.PHPExcel');//调用类库,路径是基于vendor文件夹的
        Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
        Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
        $objExcel = new \PHPExcel();
        $objActSheet = $objExcel->getActiveSheet();
        //设置表头信息
        $objActSheet->mergeCells('A1:K1'); //合并单元格
        $objActSheet->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置水平居中
        $objActSheet->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objActSheet->getStyle('A1')->getFont()->setName('宋体')->setSize(12)->setBold(true); //设置字体
        $objActSheet->setCellValue('A1','月调表');
        //列宽
        $objActSheet->getColumnDimension('A')->setWidth(10);
        $objActSheet->getColumnDimension('B')->setWidth(15);
        $objActSheet->getColumnDimension('C')->setWidth(15);
        $objActSheet->getColumnDimension('D')->setWidth(15);
        $objActSheet->getColumnDimension('E')->setWidth(15);
        $objActSheet->getColumnDimension('F')->setWidth(20);
        $objActSheet->getColumnDimension('G')->setWidth(20);
        $objActSheet->getColumnDimension('H')->setWidth(20);
        $objActSheet->getColumnDimension('I')->setWidth(20);
        $objActSheet->getColumnDimension('J')->setWidth(20);
        $objActSheet->getColumnDimension('K')->setWidth(20);
        $objActSheet->setCellValue('A2','序号');
        $objActSheet->setCellValue('B2','项目名称');
        $objActSheet->setCellValue('C2','建设单位');
        $objActSheet->setCellValue('D2','总投资');
        $objActSheet->setCellValue('E2','2020年计划投资');
        $objActSheet->setCellValue('F2','2020年完成投资');
        $objActSheet->setCellValue('G2','年度建设计划');
        $objActSheet->setCellValue('H2','截止8月底完成实物工作量');
        $objActSheet->setCellValue('I2','专班帮包情况');
        $objActSheet->setCellValue('J2','项目存在问题');
        $objActSheet->setCellValue('K2','进展照片');
    
        $list = db('xiangmu')->where('stauts = 0')->select();
        
        foreach ($list as $k => $v) {
        	$k += 3;
        	$objActSheet->setCellValue('A'.$k,$v['id']);
        	$objActSheet->setCellValue('B'.$k,$v['name']);
        	$objActSheet->setCellValue('C'.$k,$v['danwei']);
        	$objActSheet->setCellValue('D'.$k,$v['touzi']);
        	$objActSheet->setCellValue('E'.$k,$v['jihua']);
        	$objActSheet->setCellValue('F'.$k,$v['wancheng']);
        	$objActSheet->setCellValue('G'.$k,$v['jianshe']);
        	$objActSheet->setCellValue('H'.$k,$v['gongzuo']);
        	$objActSheet->setCellValue('I'.$k,$v['bang']);
        	$objActSheet->setCellValue('J'.$k,$v['wenti']);
        	$v['thumb'] = json_decode($v['thumb']);
        	// 对图片进行判断
            if(!empty($v['thumb'][0])){
                $image = '/home/wwwroot/bzshuju.itwj.cn/public'.$v['thumb'][0];
                // var_dump($image);die;
                if( @fopen($image , 'r' ) ) {
		    		//每个图片都要实例化一次
                    $objDrawing = new \PHPExcel_Worksheet_Drawing();
                    $objDrawing->setPath($image);
		    		//设置图片的宽度
                    $objDrawing->setHeight(80);
                    $objDrawing->setWidth(80);
                    $objDrawing->setCoordinates('K'.$k);
                    $objDrawing->setWorksheet($objExcel->getActiveSheet());
                }
                $objActSheet->getRowDimension($k)->setRowHeight(80);
            }
        }
        //设置打印 页面 方向与大小（此为横向）
        $objActSheet->getPageSetup()->setOrientation(\PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); 
        //设置纸张大小为A4
        $objActSheet->getPageSetup()->setPaperSize(\PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
        $outfile = "月调表.xlsx";
        //设置文档属性
        $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
        ob_end_clean();
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="'.$outfile.'"');
        header("Content-Transfer-Encoding: binary");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        $objWriter->save('php://output');
	}
	
	public function excel2()
    {
		ini_set("memory_limit","-1");
		Vendor('PHPExcel.PHPExcel');//调用类库,路径是基于vendor文件夹的
        Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
        Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
        $objExcel = new \PHPExcel();
        $objActSheet = $objExcel->getActiveSheet();
        //设置表头信息
        $objActSheet->mergeCells('A1:H1'); //合并单元格
        $objActSheet->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置水平居中
        $objActSheet->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);//垂直居中
        $objActSheet->getStyle('A1')->getFont()->setName('宋体')->setSize(12)->setBold(true); //设置字体
        $objActSheet->setCellValue('A1','基础设施建设工程表');
        //列宽
        $objActSheet->getColumnDimension('A')->setWidth(10);
        $objActSheet->getColumnDimension('B')->setWidth(15);
        $objActSheet->getColumnDimension('C')->setWidth(15);
        $objActSheet->getColumnDimension('D')->setWidth(15);
        $objActSheet->getColumnDimension('E')->setWidth(15);
        $objActSheet->getColumnDimension('F')->setWidth(20);
        $objActSheet->getColumnDimension('G')->setWidth(20);
        $objActSheet->getColumnDimension('H')->setWidth(20);
        $objActSheet->getColumnDimension('I')->setWidth(20);
        $objActSheet->getColumnDimension('J')->setWidth(20);
        $objActSheet->getColumnDimension('K')->setWidth(20);
        $objActSheet->setCellValue('A2','序号');
        $objActSheet->setCellValue('B2','项目名称');
        $objActSheet->setCellValue('C2','建设单位');
        $objActSheet->setCellValue('D2','责任单位负责人');
        $objActSheet->setCellValue('E2','计划开竣工时间');
        $objActSheet->setCellValue('F2','总体完成情况');
        $objActSheet->setCellValue('G2','本期完成情况');
        $objActSheet->setCellValue('H2','完成');
        $objActSheet->setCellValue('I2','评价');
        $list = db('jianshe')->select();
        foreach ($list as $k => $v) {
        	$k += 3;
        	$objActSheet->setCellValue('A'.$k,$v['id']);
        	$objActSheet->setCellValue('B'.$k,$v['xmmc']);
        	$objActSheet->setCellValue('C'.$k,$v['danwei']);
        	$objActSheet->setCellValue('D'.$k,$v['shijian']);
        	$objActSheet->setCellValue('E'.$k,$v['ztwcqk']);
        	$objActSheet->setCellValue('F'.$k,$v['bqwcqk']);
        	$objActSheet->setCellValue('G'.$k,$v['wancheng']);
        	$objActSheet->setCellValue('H'.$k,$v['ping']);
        }
        //设置打印 页面 方向与大小（此为横向）
        $objActSheet->getPageSetup()->setOrientation(\PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); 
        //设置纸张大小为A4
        $objActSheet->getPageSetup()->setPaperSize(\PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
        $outfile = "月调表.xlsx";
        //设置文档属性
        $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
        ob_end_clean();
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header('Content-Disposition:inline;filename="'.$outfile.'"');
        header("Content-Transfer-Encoding: binary");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Pragma: no-cache");
        $objWriter->save('php://output');
	}
}
